package com.example.demo;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RestController
public class session {
    @RequestMapping("/test1")
    @ResponseBody
    public String setsession(HttpServletRequest httpServletRequest){
        HttpSession httpSession= httpServletRequest.getSession();
        httpSession.setAttribute("a",123);
        httpSession.setAttribute("b",456);
        httpSession.setAttribute("c",789);
        httpSession.setAttribute("name",789);
        return "session设置完成";
    }

    @RequestMapping("/test2")
    public String  getsession(HttpSession httpSession){
        Integer value1= (Integer) httpSession.getAttribute("a");
        Integer value2=(Integer) httpSession.getAttribute("b");
        Integer value3=(Integer) httpSession.getAttribute("c");
        return "value1:"+value1+"value2:"+value2+"value3:"+value3;
    }
    @RequestMapping("/test3")
    public String getsession2(@SessionAttribute("name") String name){
        return name;
    }

}
